package com.tianguxx.utill;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.text.TextUtils;

public class Config implements ConfigKey
{
	private static final String CONFIG_FILE = "config";

	/**
	 *客户端版本号
	 */
	public static final String VERSION = "1";
	
	
	/**
	 * 默认的本机号码
	 */
	public static final String DEFAULT_PHONE_NUMBER = "13800138000";

	public static SharedPreferences get(Context c)
	{
		return c.getSharedPreferences(CONFIG_FILE, Context.MODE_PRIVATE);
	}

	public static Editor getEditor(Context c)
	{
		return get(c).edit();
	}

	/**
	 * 保存本机号码
	 * @param c
	 * @param phoneNumber
	 */
	public static void savePhoneNumber(Context c,String phoneNumber){
		Editor editor = getEditor(c);
		editor.putString(PHONE_NUMBER, phoneNumber);
		editor.commit();
	}
	
	/**
	 * 得到本机号码
	 * @param c
	 * @return
	 */
	public static String getPhoneNumber(Context c)
	{
		String phoneNumber = get(c).getString(PHONE_NUMBER, null);
		if (TextUtils.isEmpty(phoneNumber))
		{
			phoneNumber = MobileInformation.getSimcardMobileNumber(c);

			if (!TextUtils.isEmpty(phoneNumber))
			{
				Editor editor = getEditor(c);
				editor.putString(PHONE_NUMBER, phoneNumber);
				editor.commit();
			}
		}
		return phoneNumber;
	}
}